/**
 * 
 */
package kernel_gui.gui.extended;

import java.awt.Component;

import javax.swing.JOptionPane;


/**
 * @author Yoyo
 *
 */
public class ENewUserLoginFrame extends kernel_gui.gui.generic.graphic.NewUserLoginFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2854340163067541995L;

	public ENewUserLoginFrame(){
		setExecuteOnCancel(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(true);
				}
			}
		});
		
		setExecuteBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(false);
				}
				
			}
		});
	}

    protected void CreateUserButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
    	int requestID = executeBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				boolean ans = (Boolean) answer;
				if(ans){
					JOptionPane.showMessageDialog(ENewUserLoginFrame.this, "User was created");
					goToPreviousPage();
				}
			}
		});
    	String userName = userNameTextField.getText();
    	String password = String.valueOf(passwordTextField.getPassword());
    	String authPassword = String.valueOf(passwordAgainTextField.getPassword());
    	kernel.createUser(userName, password, authPassword,requestID);
    }                                           
                                            
    
    protected void BackButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	goToPreviousPage();
    }
    
    private void goToPreviousPage(){
    	openAnotherFrame(ELoginFrame.class, true);
    }

	@Override
	protected void setWindowComponentsWhenCalledFromAnotherFrame() {
		/*not needed*/
		
	}


}
